﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SQLDMO;

namespace Intertech.InternetSube.Resourcer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            SQLDMO.Application oSQLApp = new SQLDMO.Application();
            NameList oNames = oSQLApp.ListAvailableSQLServers();
            
            cmServerName.Items.Clear();
            cmServerName.Items.Add(new KeyValuePair("1", "Seçiniz"));
                        
            for (int i = 1; i < oNames.Count; i++)
            {
                cmServerName.Items.Add(new KeyValuePair(oNames.Item(i),oNames.Item(i)));
            }

            cmServerName.SelectedIndex = 0;
        }

        public class KeyValuePair
        {
            public object m_objKey;
            public string m_strValue;

            public KeyValuePair(object NewKey, string NewValue)
            {
                m_objKey = NewKey;
                m_strValue = NewValue;
            }

            public override string ToString()
            {
                return m_strValue;
            }
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            KeyValuePair objKeyValuePair = (KeyValuePair)cmServerName.SelectedItem;
            string strkey = objKeyValuePair.m_objKey.ToString();
            string strvalue = objKeyValuePair.m_strValue.ToString();

            if (strvalue != "-1")
            {
                StringBuilder connectionStr = new StringBuilder();
                //Data Source=s0134dbdev02;Initial Catalog=FORTUNA;User ID=webuser
                connectionStr.Append("Data Source=");
                connectionStr.Append(strvalue);
                //connectionStr.Append(
                SqlConnection sqlConnection = new SqlConnection();
            }
        }
    }
}
